<td class="rootVoice ui-corner-top <?php echo $parentNav == 'users' ? 'ui-state-active nav-actived ' : null; ?>"><?php echo $html->link('Home', '/users/home'); ?></td>
<td class="partition"></td>
<td class="rootVoice ui-corner-top <?php echo $parentNav == 'cust_stocks_in' ? 'ui-state-active nav-actived ' : null; ?>"><?php echo $html->link('Stock in', '/cust_stocks_in'); ?></td>
<?php if ($this->requestAction('sites/has_cust_reserve_stock_cout')) : ?>
    <td class="rootVoice {menu: 'customer_stock_out'} <?php echo $parentNav == 'cust_stocks_out' ? 'ui-state-active nav-actived ' : null; ?>">Stock out</td>
<?php else : ?>
    <td class="rootVoice ui-corner-top <?php echo $parentNav == 'cust_stocks_out' ? 'ui-state-active nav-actived ' : null; ?>"><?php echo $html->link('Stock out', '/cust_stocks_out'); ?></td>
<?php endif; ?>
<?php $from_supplier = $session->read('Auth.User.Extend.from_supplier');
if ($from_supplier == false) : // ถ้าเป็น Supplier เข้ามาดู เห็นแค่ Product ?>
    <td class="rootVoice {menu: 'customer_inventory'} <?php echo $parentNav == 'cust_product_sites' ? 'ui-state-active nav-actived ' : null; ?>">Inventory</td>
<?php else : ?>
    <td class="rootVoice ui-corner-top <?php echo $parentNav == 'cust_product_sites' ? 'ui-state-active nav-actived ' : null; ?>"><?php echo $html->link('Inventory', '/cust_product_sites'); ?></td>
<?php endif; ?>
<td class="partition">&nbsp;</td>
<?php
// ดูว่า Customer นี้มีเก็บคลังลูกค้าไว้ที่ Supplier หรือไม่ และต้องเป็น ลูกค้า view เอง Vendor อื่นเข้ามาดูไม่ได้
$suppliers = $this->requestAction('cust_admins/has_supplier_inventories');
if ($suppliers != null && $from_supplier == false) {
    ?>
    <td class="rootVoice {menu: 'supplier_inventory'} <?php echo $parentNav == 'supplier_inventories' ? 'ui-state-active nav-actived ' : null; ?>">Vendor Inventory</td>
    <td class="rootVoice ui-corner-top <?php echo $parentNav == 'delivery_requests' ? 'ui-state-active nav-actived ' : null; ?>">
        <?php
        $count = $this->requestAction('delivery_requests/get_on_request_count');
        echo $html->link('Delivery Request' . ($count > 0? ' (' . $count . ')': ''), '/delivery_requests');
        ?>
    </td>
    <td class="partition">&nbsp;</td>
<?php } ?>
<td class="rootVoice {menu: 'customer_return'} <?php echo $parentNav == 'main_cust_returns' ? 'ui-state-active nav-actived ' : null; ?>">Return</td>
<?php if ($session->read('Auth.User.Extend.from_supplier') == false) : // ถ้ามาจาก supplier ไม่ต้องเห็น Message, Report ?>
    <?php if ($session->read('Auth.User.read_message') == true) : ?>
        <td class="rootVoice ui-corner-top <?php echo $parentNav == 'messages' ? 'ui-state-active nav-actived ' : null; ?>"><?php echo $html->link('Message' . (($message_count = $this->requestAction('messages/new_message_count')) > 0 ? ' (' . $message_count . ')' : ''), '/messages'); ?></td>
    <?php endif; ?>

    <?php if ($session->read('Auth.User.cust_report') == true) : ?>
        <td class="rootVoice {menu: 'customer_report'} <?php echo $parentNav == 'cust_reports' ? 'ui-state-active nav-actived ' : null; ?>">Report</td>
    <?php endif; ?>
<?php endif; ?>

<!-- sub menu -->
<div id="customer_inventory" class="menu hide">
    <?php echo $html->link('Product', array('controller' => 'cust_product_sites', 'action' => 'display')); ?>
    <?php echo $html->link('Location', array('controller' => 'cust_locations', 'action' => 'display')); ?>
</div>
<div id="customer_report" class="menu hide">
    <?php echo $html->link('Stock in', array('controller' => 'cust_reports', 'action' => 'stock_in_search')); ?>
    <a class="{menu: 'sub_menu_stock_out_report'}">Stock out</a>
</div>

<div id="sub_menu_stock_out_report" class="menu hide">
    <?php echo $html->link('Group by Cost Center', array('controller' => 'cust_reports', 'action' => 'stock_out_cost_center_search')); ?>
    <?php echo $html->link('Group by Part', array('controller' => 'cust_reports', 'action' => 'stock_out_search')); ?>
</div>
<div id="customer_return" class="menu hide">
    <?php
    echo $html->link('Return to Inventory', array('controller' => 'cust_stock_out_returns', 'action' => 'display'));
    // ถ้า view มาจาก Supplier ไม่ต้องเป็น return to its และ title ไม่ต้องมีคำว่า Other
    if ($session->read('Auth.User.Extend.from_supplier') == true) {
        $title = 'Return to Vendor';
    } else {
        $title = 'Return to Other Vendor';
        echo $html->link('Return to ITS', array('controller' => 'cust_returns', 'action' => 'display'));
    }
    echo $html->link($title, array('controller' => 'cust_return_to_suppliers', 'action' => 'display'));
    if ($suppliers != null && $from_supplier == false) {
        echo $html->link('Delivery Return', array('controller' => 'delivery_returns', 'action' => 'display'));
    }
    ?>

</div>
<div id="customer_stock_out" class="menu hide">
    <?php echo $html->link('Stock out', array('controller' => 'cust_stocks_out', 'action' => 'display')); ?>
    <?php echo $html->link('Reserve', array('controller' => 'cust_reserves', 'action' => 'display')); ?>
</div>


<div id="supplier_inventory" class="mbmenu">
    <?php
    $customer_id = $session->read('Auth.User.customer_id');
    $site_id = $session->read('Auth.User.site_id');
    foreach ($suppliers as $sup) {
        echo $html->link($sup['Supplier']['name'], array('controller' => 'supplier_inventories', 'action' => 'display', $customer_id, $site_id, 'supplier_id' => $sup['Supplier']['id']));
    }
    ?>
</div>